/**
 * PayCommonUtil.java
 * cn.ccig.terminal.pay.weixin.util
 * Copyright (c) 2015, 北京 快先生科技有限公司版权所有.
*/

package com.sftz.modules.minapp.pay.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author   朱晓川
 * @Date	 2015-8-6 	 
 */
public class PayCommonUtil {

	/**
	 * 获取请求微信接口时的xml数据
	 */
	public static String getRequestXml(Map<String, Object> params) {
		StringBuffer sb = new StringBuffer();
		sb.append("<xml>");
		Set es = params.entrySet();
		Iterator it = es.iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			String k = (String) entry.getKey();
			String v = entry.getValue().toString();
			if ("attach".equalsIgnoreCase(k) || "body".equalsIgnoreCase(k) || "sign".equalsIgnoreCase(k)) {
				sb.append("<" + k + ">" + "<![CDATA[" + v + "]]></" + k + ">");
			} else {
				sb.append("<" + k + ">" + v + "</" + k + ">");
			}
		}
		sb.append("</xml>");
		return sb.toString();
	}

	/**
	 * 获取响应给微信的xml数据
	 */
	public static String getResponseXML(String returnCode, String returnMsg) {
		return "<xml><return_code><![CDATA[" + returnCode + "]]></return_code><return_msg><![CDATA[" + returnMsg
				+ "]]></return_msg></xml>";

	}

}
